

package examples.radio;

import commandz.cli.*;
import commandz.var.*;
import java.util.Collection;


/**
 *  Command for tuning the radio to another station.
 */
public final class TuneCommand implements Command
{
    private VariableReal frequency;
    private Radio radio;


    public TuneCommand(Radio radio)
    {
        this.radio = radio;
        this.frequency = new VariableReal();
    }


    public String getName()
    {
        return "tune";
    }


    public String getDescription()
    {
        return "Tunes the radio to the given frequency.";
    }


    public void publishParameters(Collection<Parameter> params)
    {
        params.add(new Parameter(this.frequency, "frequency", "A frequency."));
    }


    public void execute()
    {
        this.radio.setFrequency(this.frequency.getValue());

        System.out.printf("Frequency: %.2f %s.\n",
                this.radio.getFrequency(), this.radio.getModulation());
    }
}
